#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
struct Comp {
  bool operator() (ii a,ii b) {
    return a.first<b.first;
  }
};
int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  priority_queue<ii, deque<ii>, Comp> iq;
  string buf;
  int i1,i2;
  while(cin >> buf) {
    if(buf=="IN") {
      cin>>i1>>i2;
      iq.emplace(i1,i2);
    }
    else if(buf=="OUT") {
      cin>>i1>>i2;
      iq.pop();
    }
  }
  
  return 0;
}
